﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
    .item {
        display: inline-block;
        padding: 15px;
    }

    .item .label {
        display: inline-block;
        width: 70px;
        text-align: right;
    }
</style>
<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
    <table width="1000px;">
        <tr>
            <td width="1000px;">
                <a class="mini-button" id="save" name="save" iconcls="icon-save" onclick="save" plain="true">保存</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>
</div>

<form id="form1" runat="server" method="post" style="height: 100%">
    <div class="mini-fit" >
        <div id="tabs1" class="mini-tabs" activeIndex="0"  style="width:100%; height:100%; top: 0px; left: 0px;overflow:hidden;" plain="false">
            <div id="KillMain" name="SelectGood" title="秒杀方案" style="height:100%;overflow:hidden;margin-left:20px; margin-top:5px;">
                <div>
                    <div class="item">
                        <label class="label">开始时间:</label>
                        <input id="startDate" class="mini-datepicker" style="width: 200px;" format="yyyy-MM-dd HH:mm" showTime="true" allowInput="false" showOkButton="true" ondrawdate="onDrawDate"/>
                    </div>
                    <div class="item">
                        <label class="label">结束时间:</label>
                        <input id="endDate" class="mini-datepicker" style="width: 200px;" format="yyyy-MM-dd HH:mm" showTime="true" allowInput="false" showOkButton="true" ondrawdate="onDrawDate"/>
                    </div>
                </div>
                <div>
                    <div class="item">
                        <label class="label">门店:</label>
                        <div style="display: inline-block;vertical-align: middle;">@Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")</div>
                    </div>
                    <div class="item">
                        <label class="label">是否启用:</label>
                        <div id="isEnabled" class="mini-checkbox"text="是"></div>
                    </div>
                </div>
                <div>
                    <div class="item">
                        <label class="label">提成金额: </label>
                        <div style="display: inline-block;vertical-align: middle;">
                            <input id="FRebate" name="FRebate" class="mini-spinner" changeOnMousewheel ="false" minValue="0"  maxValue="9999999"
                                    style="width: 200px;" showbutton="false" allowNull="true"/>
                        </div>
                    </div>
                    <div class="item">
                    </div>
                </div>
            </div>
            <div name="img" title="活动展示图" style="height:20%;overflow:hidden;font-size:12pt;top: 5px; left: 0px;">
                <table style="margin-top:15px;">
                    <tr>
                        <td width="80px" align="right">展示图：</td>
                        <td colspan="3" align="left">
                            <input type="text" id="FLogoUrl" name="FLogoUrl" class="mini-hidden" enabled="false" required="true" width="200px" />
                            <span class="btn btn-success fileinput-button" style="margin-left: 0px;margin-top: 20px;">
                                <img id="Image" src="~/Content/Images/NoImage.jpg" width="200" height="150" />
                                <input id="myfile" type="file" accept=".jpg,.png"><br />
                                <span>图像尺寸: 351 * 178</span>
                            </span>
                        </td>
                    </tr>
                </table>
            </div>
            <div name="mark" title="活动说明" style="height:20%;overflow:hidden;font-size:12pt;top: 5px; left: 0px;">
                <input id="FIntro" name="FIntro" class="mini-textarea "  style="width:635px;height:270px;"/><br />
                <span style="color:#5c5c5c;font-size:14pt;">(要求在200字以内)</span>
            </div>
            <div name="mark" title="规则说明" style="height:20%;overflow:hidden;font-size:12pt;top: 5px; left: 0px;">
                <input id="FRuleIntro" name="FRuleIntro" class="mini-textarea "  style="width:635px;height:270px;"/><br />
                <span style="color:#5c5c5c;font-size:14pt;">(要求在200字以内)</span>
            </div>

        </div>
    </div>

    <input id="FItemID" class="mini-hidden" value="0"/>
</form>
<script src="~/Scripts/jquery-1.11.1.min.js"></script>
<script src="~/Scripts/common.js"></script>
<script>
    mini.parse();
    function SetData(data) {
        mini.get("FItemID").setValue(data.FItemID);
        getData();
    }

    $(function () {
        $("#myfile").change(function () {
            var formData = new FormData();
            formData.append("myfile", document.getElementById('myfile').files[0]);
            formData.append("mSystemAppID", parent.window.getSystemAppID());            
            $.ajax({
                url: "/Upload/UploadFile",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                success: function (res) {
                    if (res.status == 1) {
                        $("#Image").attr("src", res.path);
                        alert(res.logoUrl);
                        mini.get("FLogoUrl").setValue(res.logoUrl);
                    }
                }
            });
        });
    });

    function getData() {
        var param = {
            FItemID: mini.get("FItemID").getValue()
        }
        postRequest("/Coupon/GetSeckillClassInfo", param, function (res) {
            if (res.status == 1) {
                mini.get("startDate").setValue(res.data[0].FStartDate);
                mini.get("endDate").setValue(res.data[0].FEndDate);
                mini.get("FStockID").setValue(res.data[0].FStockID);
                mini.get("isEnabled").setChecked(res.data[0].FIsEnabled == "1");
                mini.get("FStockName").setValue(res.data[0].FStockName);
                mini.get("FStockID").setText(res.data[0].FStockNumber);
                mini.get("FIntro").setValue(res.data[0].FIntro);
                mini.get("FRuleIntro").setValue(res.data[0].FRuleIntro);
                mini.get("FRebate").setValue(res.data[0].mFRebate3);
                $("#Image").attr("src", res.data[0].FPicUrl);
                mini.get("FLogoUrl").setValue(res.data[0].FPicUrl);
            } else {
                mini.showTips({ content: res.msg, state: "danger", x: "center", y: "top", timeout: 3000 });
            }
        });
    }

    function CloseWindow(action) {
        if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);
        else window.close();
    }

    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();

        if (date.getTime() < d.getTime()) {
            e.allowSelect = false;
        }
    }

    function save() {
        var startDate = mini.get('startDate').getText();
        var endDate = mini.get('endDate').getText();
        var stockId = mini.get('FStockID').getValue();
        var isEnabled = mini.get("isEnabled").getChecked() ? 1 : 0;
        if (startDate == "") {
            mini.alert("请选择开始时间!");
            return;
        }
        if (endDate == "") {
            mini.alert("请选择结束时间!");
            return;
        }
        if (mini.getbyName("FIntro").getValue().length > 200) {
            mini.alert("活动说明字数太多，要求最大200字。");
            return;
        }
        if (mini.getbyName("FRuleIntro").getValue().length > 200) {
            mini.alert("活动规则字数太多，要求最大200字。");
            return;
        }
        var param = {
            startDate: startDate,
            endDate: endDate,
            stockId: stockId,
            isEnabled: isEnabled,
            FItemID: mini.get('FItemID').getValue(),
            sSystemAppID: parent.window.getSystemAppID(),
            FPicUrl: mini.get('FLogoUrl').getValue(),
            FIntro: mini.get('FIntro').getValue(),
            FRuleIntro: mini.getbyName('FRuleIntro').getValue(),
            FRebate: mini.getbyName('FRebate').getValue()
        }
        debugger;
        postRequest("/Coupon/SaveSeckillClass", param, function(res) {
            if (res.status == 1) {
                mini.showTips({ content: res.msg, state: "success", x: "center", y: "top", timeout: 3000 });
            } else {
                mini.alert(res.msg);
            }
        });
    }

</script>
